package pl.edu.agh.mwo.ui.action;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.File;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFileChooser;

import pl.edu.agh.mwo.model.MenadzerPracownikow;
import pl.edu.agh.mwo.model.Pracownik;
import pl.edu.agh.mwo.model.dataimport.FolderReader;
import pl.edu.agh.mwo.ui.app.MainApp;

public class ImportAction extends AbstractAction {

	private static final long serialVersionUID = -2206397237479809080L;
	private Component component;
	private MenadzerPracownikow mp;
	private MainApp ma;

	public ImportAction(Component component, MenadzerPracownikow mp, MainApp ma) {
		this.component = component;
		this.mp = mp;
		this.ma = ma;
		putValue(NAME, "Importuj dane");
		putValue(SHORT_DESCRIPTION, "Shows about dialog");
		putValue(Action.MNEMONIC_KEY, new Integer('A'));

	}

	@Override
	public void actionPerformed(ActionEvent event) {
		final JFileChooser fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

		int returnVal = fc.showOpenDialog(component);

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			File file = fc.getSelectedFile();
			// This is where a real application would open the file.
			FolderReader fr = new FolderReader(file, mp);
			try {
				fr.xlsFilesRead(file);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();

			}
			// TODO
			ma.updateTable();
			
		//	for (Pracownik p : mp.getListaPracownikow()) {
		//		System.out.print(p.getImie()+" ");		
		//		System.out.print(p.getNazwisko()+ " ");
		//		System.out.println(p.getZbiorczyCzasPracy()+" ");
		//			}

		} else {

		}

	}
}